<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background: red;
        }
        .active{
            color: white;
        }
    </style>
</head>
<body>
    <div class="box">hello</div>
    <button>点击1</button>
    <button>点击2</button>
    <script>
        // var ele = document.querySelector(".box");
        // ele.onclick = function(){
        //     this.className += " active";
        // }

        // 操作类名  classList 对象 来操作类名；
        var ele = document.querySelector(".box");
        // 1.添加类名 classList.add("类名");
        ele.onclick = function(){
            this.classList.add("active");
        }
        // 2.移除某个类名；classList.remove("类名");
    //     var str = "box active";
    //   var res =   str.replace(" active","");
    //   console.log(res);
        var btns = document.querySelectorAll("button");
        btns[0].onclick = function(){
            ele.classList.remove("active");
        }

        // 3.判断元素是否包含某个类名；classList.contains
        btns[1].onclick = function(){
           var res =  ele.classList.contains("active");
           console.log(res);
        }


    </script>
</body>
</html>